package servlet;

import entity.User;
import lombok.SneakyThrows;
import serviceImpl.invitate;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "InviteServlet", value = "/InviteServlet")
public class InviteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");

        String id=request.getParameter("id");
        invitate in=new invitate();

        User user = (User)request.getSession().getAttribute("user");
        System.out.println("       登录的用户id为"+user.getId());
        System.out.println("   邀请的用户id为"+id);
        boolean t= in.invitate(user, id, "快来加入我的小组吧!");

        String text="";

        if(t==true){
            text="邀请成功!邀请id为"+id;
        }
        else{
            text="不存在用户ID！";
        }
        System.out.println(text);

        PrintWriter out=response.getWriter();
        out.print(text);
    }
}
